<script>
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import store from '@/store/index.ts'
	// import amap from '@/utils/amap-wx.js'
	export default {
		onLaunch: function() {
			// uni.getLocation({
			// 	type: 'wgs84',
			// 	success: function (res) {
			// 		console.log(res);
			// 		const amapPlugin = new amap.AMapWX({
			// 		    key: '76f75a756206be1c66db1dc19819b092'  
			// 		});
			// 		amapPlugin.getRegeo({
			// 			success: (data) => {
			// 				console.log(data)
			// 			},
			// 			fail: err => {
			// 				console.log(err)
			// 				uni.showToast({
			// 					title: '自动地位失败',
			// 					icon: 'none'
			// 				})
			// 			}
			// 		})
			// 	}
			// });
			// 获取义购之家购物车数量
			store.dispatch('getCartNumData')
			// 底部安全距离计算
			// #ifdef MP-WEIXIN
			this.getBottomSafeArea()
			// #endif
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		data() {
			return {
				bottomSafeArea: null
			}
		},
		methods: {
			// 底部安全距离计算
			getBottomSafeArea() {
				const result = wx.getSystemInfoSync()
				// 获取菜单按钮（右上角胶囊按钮）的布局位置信息
				const capsuleInfo = wx.getMenuButtonBoundingClientRect()
				// 胶囊热区 = 胶囊和状态栏之间的留白 * 2 (保持胶囊和状态栏上下留白一致) * 2(设计上为了更好看) + 胶囊高度
				const navbarHeight = (capsuleInfo.top - result.statusBarHeight) * 4 + capsuleInfo.height
				// 写入胶囊数据
				result.capsuleInfo = capsuleInfo;
				// 安全区域
				const safeArea = result.safeArea
				// 可视区域高度 - 适配横竖屏场景
				const screenHeight = Math.max(result.screenHeight, result.screenWidth)
				const height = Math.max(safeArea.height, safeArea.width)
				// 状态栏高度
				const statusBarHeight = result.statusBarHeight
				// 获取底部安全区域高度（全面屏手机）
				if (safeArea && height && screenHeight) {
					result.bottomSafeHeight = screenHeight - height - statusBarHeight
					this.bottomSafeArea = result.bottomSafeHeight
					if (result.bottomSafeHeight < 0) {
						result.bottomSafeHeight = 0
						this.bottomSafeArea = result.bottomSafeHeight
					}
				}
				uni.setStorageSync('bottomSafeArea', this.bottomSafeArea)
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import url("static/style/common.css");
	/* 引入图标库 */
	@import url("static/style/iconfont.css");
	/*公共样式 */
	@import "@/static/style/main.scss";
</style>